package metricsdata;



/**
 * Factory to create a new metric based on value (as String) and metricID (from @MetricNamesInterface).
 * @author Nico
 *
 */
public class MetricFactory {
	
	
	
	public static AbstractMetricAttribute createMetric(String value, String[] metadata){
		return createMetric(value, metadata[0],metadata[1],metadata[2],metadata[5]);
	}
	
	/**
	 * Factory method to create a new metric based on value (as String) and metricID (from @MetricNamesInterface).
	 * @param value 
	 * 		metric value as String.
	 * @param shortcut
	 * 		Metric name shortcut (e.g. CYCLO)
	 * @param fullName
	 * 		Metric name full quantifier: e.g. McCabe Cyclomatic Complexity
	 * @param description
	 * 		Metric definition: e.g. CYCLO is calculated as number of decision points in a function.
	 * @return
	 * 		a new metric object of the right type (e.g. DoubleValueMetric)
	 */
	public static AbstractMetricAttribute createMetric(String value, String shortcut, String fullName, String description, String type){
		
		AbstractMetricAttribute result = null;
		
		//decide which metric to create: information stored in MetricNamesInterface
		if(type.equals("metricsdata.DoubleValueMetric")){
			result = new DoubleValueMetric(value,shortcut,fullName,description);
		}
		else if(type.equals("metricsdata.DoubleArrayValueMetric")){
			result = new DoubleArrayValueMetric(value,shortcut,fullName,description);
		}
		else if(type.equals("metricsdata.IntegerValueMetric")){
			result = new IntegerValueMetric(value,shortcut,fullName,description);
		}
		else if(type.equals("metricsdata.IntegerArrayValueMetric")){
			result = new IntegerArrayValueMetric(value,shortcut,fullName,description);
		}
		else if(type.equals("metricsdata.IntegerArray2ValueMetric")){
			result = new IntegerArray2ValueMetric(value,shortcut,fullName,description);
		}
		else if(type.equals("metricsdata.DoubleArray2ValueMetric")){
			result = new DoubleArray2ValueMetric(value,shortcut,fullName,description);
		}
		
		if(result == null){
			System.out.println("Metric Factory: Type not known for "+type);
		}
		
		return result;
	}
}
